/*
 *  $Id: DarkOrder.cs 1014 2010-05-11 20:18:48Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2009 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Darkness.Abilities {
    public class DarkOrder: AbilityCard<ChainData> {
        public DarkOrder(): base("001_d_a_dark_order") {
            Level = CompleteLevel.ReadyForTest;
            Version = 0;
            Element = ElementType.Darkness;
            Target = new ChainTarget(null,
                new CreatureTarget(GetNewPhrase("target1"), true, false, CreatureTarget.IsNotSelf),
                new GraveyardTarget(GetNewPhrase("target2"), true, true, CanResurrect));
            AddCondition(new CreaturesCondition(true, 1));
        }

        private static bool CanResurrect(TargetRequest request, GraveyardItem item) {
            return item.CanResurrect && item.Undead;
        }

        private static readonly Languages.CardPhrase<DarkOrder> Action = new Languages.CardPhrase<DarkOrder>("action");

        protected override void DoAction(TargetArgs<ChainData> args) {
            TargetArgs<Creature> ca;
            TargetArgs<GraveyardData> ga;
            if (!args.Target.GetArgs(out ca, out ga)) return;
            int place = args.Player.GetRandomFreePlace();
            if (place < 0) return;
            args.Player.Game.Log.Add(Action.Phrase, args.Caster, ga.Target.Item.Card);
            ca.Target.InstantDeath();
            ga.Target.Owner.ResurrectCreatureToPlayer(args.Player, ga.Target.Item, place, false);
        }
    }
}
